Adds "this-is-scam" message context command#1505
Conversation
|
| @SuppressWarnings("squid:S3457") // %n is wrong, markdown must use \n | ||
| private static String createDescription(Message target) { |
There was a problem hiding this comment.
Couldn't you easily use multiline strings here to make it cleaner and get rid of the suppress warnings?
| private boolean handleCanQuarantineAndBan(Guild guild, Member target, | ||
| ButtonInteractionEvent event) { | ||
| Member bot = guild.getSelfMember(); | ||
| Member moderator = Objects.requireNonNull(event.getMember()); | ||
| Role quarantinedRole = ModerationUtils.getQuarantinedRole(guild, config).orElse(null); | ||
|
|
||
| return ModerationUtils.handleRoleChangeChecks(quarantinedRole, "quarantine", target, bot, | ||
| moderator, guild, ACTION_REASON, event) | ||
| && ModerationUtils.handleHasBotPermissions("ban", Permission.BAN_MEMBERS, bot, | ||
| guild, event); | ||
| } | ||
|
|
||
| private RestAction<Boolean> sendQuarantineDm(User target, Guild guild) { | ||
| String description = | ||
| """ | ||
| Hey there, sorry to tell you but unfortunately you have been put under quarantine. | ||
| This means you can no longer interact with anyone in the server until you have been unquarantined again."""; | ||
|
|
||
| return ModerationUtils.sendModActionDm(ModerationUtils.getModActionEmbed(guild, | ||
| ACTION_TITLE, description, ACTION_REASON, true), target); | ||
| } | ||
|
|
||
| private RestAction<Void> quarantineUser(Guild guild, Member target, Member moderator) { | ||
| logger.info(LogMarkers.SENSITIVE, | ||
| "'{}' ({}) quarantined the user '{}' ({}) in guild '{}' for reason '{}'.", | ||
| moderator.getUser().getName(), moderator.getId(), target.getUser().getName(), | ||
| target.getId(), guild.getName(), ACTION_REASON); | ||
|
|
||
| actionsStore.addAction(guild.getIdLong(), moderator.getIdLong(), target.getIdLong(), | ||
| ModerationAction.QUARANTINE, null, ACTION_REASON); | ||
|
|
||
| return guild | ||
| .addRoleToMember(target, | ||
| ModerationUtils.getQuarantinedRole(guild, config).orElseThrow()) | ||
| .reason(ACTION_REASON); | ||
| } | ||
|
|
||
| private RestAction<Void> deleteMessagesByBanAndUnban(Guild guild, User target) { | ||
| return guild.ban(target, 1, TimeUnit.DAYS) | ||
| .reason(ACTION_REASON) | ||
| .flatMap(_ -> guild.unban(target).reason(ACTION_REASON)); | ||
| } | ||
| } |
There was a problem hiding this comment.
Can't all of this be reused from the existing quarantine/moderation logic?
There was a problem hiding this comment.
not easily. but yeah, some of it can probably be moved around.
the main issue is that we only want part of the behavior but not everything.
so moving the code around could possibly result in making it too complex to understand.
but its a good comment, ill have a second look :)
firasrg
left a comment
There was a problem hiding this comment.
Thank you @Zabuzard for the great work you've put into this. I'm genuinely impressed by the scope of the changes and the amount of effort behind them.
I've left comments, mostly focused on long-term maintainability and readability. I didn't spend much time reviewing the logic itself, as I trust you've given that aspect the attention it deserves.
| * Allows users to report a message as potential scam. Moderators can confirm the report from the | ||
| * audit log, causing the author to be quarantined plus message history getting deleted. | ||
| */ | ||
| public final class ThisIsScamCommand extends BotCommandAdapter implements MessageContextCommand { |
There was a problem hiding this comment.
I'd use a name like ScamReportCommand for the class, and for the command scam-report
There was a problem hiding this comment.
imo all that does is making it more confusing for the user and the devs. a context command needs to be a verb, especially bc they dont have any description in the discord ui
There was a problem hiding this comment.
Both work fine, agree it's NIT
There was a problem hiding this comment.
imo all that does is making it more confusing for the user and the devs. a context command needs to be a verb, especially bc they dont have any description in the discord ui
Then "Report Scam"
There was a problem hiding this comment.
I will join the "it's a NIT" team here. It's just the name at the end of the day, and the class has a JavaDoc which makes it easier to understand what this class focuses on.
| .build(); | ||
|
|
||
| private final Config config; | ||
| private final ModerationActionsStore actionsStore; |
There was a problem hiding this comment.
I'd put these 2 fields config and actionsStore above reportedMessageToTimestamp and userToLastCommandUse, because they represent a higher level
There was a problem hiding this comment.
I agree that this is a NIT comment.
At the very least this should be handled by our Spotless plugin.
| @SuppressWarnings("squid:S3457") // %n is wrong, markdown must use \n | ||
| private static String createDescription(Message target) { | ||
| String content = target.getContentStripped(); | ||
| String description = content.isBlank() ? "(empty message)" : content; |
There was a problem hiding this comment.
i'd rather say "empty description"
There was a problem hiding this comment.
that would be confusing as "description" is right in the context of the embed but not in the context of the reading user in discord.
the scan message that was reported is empty, so that is what we need to tell the user.
empty message.
i might improve the wording slightly though:
(message had no text content)
christolis
left a comment
There was a problem hiding this comment.
LGTM. Thank you for your contribution 👍
| * Allows users to report a message as potential scam. Moderators can confirm the report from the | ||
| * audit log, causing the author to be quarantined plus message history getting deleted. | ||
| */ | ||
| public final class ThisIsScamCommand extends BotCommandAdapter implements MessageContextCommand { |
There was a problem hiding this comment.
I will join the "it's a NIT" team here. It's just the name at the end of the day, and the class has a JavaDoc which makes it easier to understand what this class focuses on.
| .build(); | ||
|
|
||
| private final Config config; | ||
| private final ModerationActionsStore actionsStore; |
There was a problem hiding this comment.
I agree that this is a NIT comment.
At the very least this should be handled by our Spotless plugin.



Overview
This adds a new message context command (right click message) called
this-is-scam. It acts as the primary way for users to report scam to mods.Mods then get presented a quick way to handle the scam properly by automatically deleting all messages from the user and putting them under quarantine through a single button press!
Internally this works by quarantine, ban (delete messages from one day), unban in that order. The user ends up being kicked out of the guild (due to the ban) but can immediately rejoin (due to the unban), but remains quarantined.
Other
The following extra situations are handled gracefully via in-memory caches:
Also, an appropriate entry in the audit-log of the user (
/audit) is created.Attachments are spelled out so it becomes easier for devs later on to edit
ScamBlockeraccordingly.Code
The integration is minimal and simple, just a straightforward single class is added
ThisIsScamCommand.java, thats it. No config changes, everything easy.Impressions
Context Menu
Response
What mods see
No scam
Yes scam
DM
Quarantined
Audit Log
Edge cases
Error